package com.example.springwebdemo1.service.impl;


import cn.hutool.core.io.IoUtil;
import com.example.springwebdemo1.dao.UserDao;
import com.example.springwebdemo1.dao.impl.UserDaoImpl1;
import com.example.springwebdemo1.pojo.User;
import com.example.springwebdemo1.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class UserServiceImpl implements UserService {
   @Autowired
   private UserDao userDao;
   public List<User> findAll(){
      //2.解析用户信息，封装成User对象
      List<String> lines=userDao.findAll();
      List<User> userList=lines.stream().map(line->{
         String[] array=line.split(",");
         Integer id=Integer.parseInt(array[0]);
         String username=array[1];
         String password=array[2];
         String name=array[3];
         Integer age=Integer.parseInt(array[4]);
         LocalDateTime updateTime=LocalDateTime.parse(array[5], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
         return new User(id,username,password,name,age,null);
      }).collect(Collectors.toList());
      //3.返回数据（json）
      return userList;
   }
   }
